package com.ctsi.ssdc.controller.front;

import com.ctsi.ssdc.common.R;
import com.ctsi.ssdc.constants.SortedMapConstant;
import com.ctsi.ssdc.entity.SubDistrictTownIndustrialInvestment;
import com.ctsi.ssdc.service.front.TradeAndServiceService1;
import com.ctsi.ssdc.entity.SocialRetailSales;
import com.ctsi.ssdc.entity.TradeAndServiceIndustry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@RestController
@RequestMapping("/tradeAndService")
public class TradeAndServiceController1 {
    @Autowired
    TradeAndServiceService1 tradeAndServiceService1;

    /**
     *分区镇社会消费品零售总额
     *
     * @param year(int) 年份, month(int) 月份
     *@return
     * List集合（SocialRetailSales类）
     *                {id
     *                 indicators
     *                 thisMonth
     *                 accumulate
     *                 monthOnMonth
     *                 growthRanking
     *                 statisticalTime
     *                 year
     *                 month}
     *
     */
    @GetMapping("/getSocialRetailSales")
    @CrossOrigin
    public R getSocialRetailSales(@RequestParam int year, @RequestParam int month) {
        List<SocialRetailSales> allInfoList = tradeAndServiceService1.getSocialRetailSales(year, month);
        if(allInfoList == null || allInfoList.isEmpty()) return R.miss("不存在该信息");
        SocialRetailSales total =  null;
        SocialRetailSales zhou_zhuang = null; // 周庄
        SocialRetailSales dian_shan_hu = null; // 淀山湖
        SocialRetailSales jin_xi = null; // 锦溪
        List<SocialRetailSales> fiexedList = new ArrayList<>();
        List<SocialRetailSales> sortedList = new ArrayList<>();
        for (SocialRetailSales industry : allInfoList) {
            switch (industry.getIndicators()) {
                case "全市总计":
                    total = industry;
                    break;
                case "周庄镇":
                    zhou_zhuang = industry;
                    break;
                case "淀山湖镇":
                    dian_shan_hu = industry;
                    break;
                case "锦溪镇":
                    jin_xi = industry;
                    break;
                default:
                    fiexedList.add(industry);
                    sortedList.add(industry);
            }
        }
        fiexedList.sort(Comparator.comparingInt(a -> SortedMapConstant.get(a.getIndicators())));
        return R.ok().data("total", total).data("zhou_zhuang", zhou_zhuang)
                .data("dian_shan_hu", dian_shan_hu).data("jin_xi", jin_xi)
                .data("fiexedList", fiexedList).data("sortedList", sortedList);
    }

    /**
     * 限上批发业销售额
     * 限上零售业销售额
     * 限上住宿业营业额
     * 限上餐饮业营业额
     * 交通及营利性服务业营业额
     * 房地产销售收入
     * 房地产销售面积（万平方米）
     *
     * @param year(int) 年份, indicators(String) 指标
     *@return
     * List集合（SocialRetailSales类）
     *                {id
     *                 indicators
     *                 thisMonth
     *                 accumulate
     *                 monthOnMonth
     *                 statisticalTime
     *                 year
     *                 month}
     *
     */
    @GetMapping("/getTradeAndServiceByIndicators")
    @CrossOrigin
    public List<TradeAndServiceIndustry> getTradeAndServiceByIndicators(@RequestParam int year, @RequestParam String indicators) {
        return tradeAndServiceService1.getTradeAndServiceByIndicators(year,indicators);
    }



    /**
     *头标：当月及当月累计
     *
     * @param year(int) 年份, month(int) 月份, indicators(String) 指标
     *@return
     * TradeAndServiceIndustry类
     *                {id
     *                 indicators 指标
     *                 thisMonth 当月
     *                 accumulate 当月累计
     *                 monthOnMonth 同比
     *                 statisticalTime 日期
     *                 year 年
     *                 month 月}
     *
     */
    @GetMapping("/getMonthProduct")
    @CrossOrigin
    public TradeAndServiceIndustry getMonthProduct(@RequestParam int year, @RequestParam int month, @RequestParam String indicators) {
        return tradeAndServiceService1.getMonthProduct(year, month, indicators);
    }
}
